<?php

require_once 'model/mLogin.php';

class aLogin extends mLogin {

    protected $sqlInsert = "INSERT INTO login () VALUES ('', '%s', '%s', '%s', '%s')";
    protected $sqlUpdate = "UPDATE login SET senha='%s' WHERE id_login='%s'";
    protected $sqlDelete = "DELETE FROM login WHERE id_login='%s'";
    protected $sqlSelect = "SELECT * FROM login WHERE 1=1 %s %s ";
    protected $sqlLoado = "UPDATE login SET logado='%s' WHERE id_login='%s'";

    public function insert() {
        $sql = sprintf($this->sqlInsert, $this->getUsuario(), $this->getSenha(), $this->getLogado(), $this->getTipo());
        return $this->runQuery($sql);
    }

    public function update() {
        $sql = sprintf($this->sqlUpdate, $this->getUsuario(), $this->getIdLogin());
        return $this->runQuery($sql);
    }

    public function delete() {
        $sql = sprintf($this->sqlDelete, $this->getIdLogin());
        return $this->runQuery($sql);
    }

    public function select($where = '', $order = '') {
        $sql = sprintf($this->sqlSelect, $where, $order);
        return $this->runSelect($sql);
    }

    public function load() {
        $rs = $this->select(sprintf("and id_login='%s'", $this->getIdLogin()));
        $this->setIdLogin($rs[0]['id_login']);
        $this->setUsuario($rs[0]['usuario']);
        $this->setSenha($rs[0]['senha']);
        $this->setLogado($rs[0]['logado']);
        return $this;
    }

    public function logado($logado) {
        $sql = sprintf($this->logado(), $this->getIdLogin(), $logado);
        return $this->runQuery($sql);
    }

}

?>
